package com.hpf.cloud.controller;

import com.hpf.cloud.entity.Dept;
import com.hpf.cloud.apis.IAdminServiceFeign;
import com.hpf.cloud.pojo.CommonResult;
import com.hpf.cloud.pojo.PageResult;
import com.hpf.cloud.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Fred
 * @since 2020-11-22
 */
@RestController
@RequestMapping("/dept")
@Slf4j
public class DeptController {


    @Autowired
    private DeptService deptService;

    @Resource
    private IAdminServiceFeign iAdminServiceFeign;

    @GetMapping(value = "/test")
    public CommonResult list(@RequestParam(required = false) Integer current, @RequestParam(required = false) Integer pageSize) {

        CommonResult list = iAdminServiceFeign.list(1,10);
        log.info("list-------->{}",list.getData());
        return PageResult.ok(list.getData());
    }

    @GetMapping(value = "/{id}")
    public ResponseEntity<Dept> getById(@PathVariable("id") String id) {
        return new ResponseEntity<>(deptService.getById(id), HttpStatus.OK);
    }

    @PostMapping(value = "/create")
    public ResponseEntity<Object> create(@RequestBody Dept params) {
        deptService.save(params);
        return new ResponseEntity<>("created successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/delete/{id}")
    public ResponseEntity<Object> delete(@PathVariable("id") String id) {
        deptService.removeById(id);
        return new ResponseEntity<>("deleted successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/update")
    public ResponseEntity<Object> delete(@RequestBody Dept params) {
        deptService.updateById(params);
        return new ResponseEntity<>("updated successfully", HttpStatus.OK);
    }
}
